<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>管理项目</title>
    <!--公用样式-->
    <link rel="stylesheet" type="text/css" href="${re.contextPath}/plugin/common/css/comment.css"/>
    <!--页面样式-->
    <link rel="stylesheet" type="text/css" href="${re.contextPath}/plugin/supplier/common/css/style.css"/>
    <!--Layui-->
    <link rel="stylesheet" href="${re.contextPath}/plugin/layui2.6.7/css/layui.css" media="all"/>
    <!--layui-dropdown-->
    <link rel="stylesheet" type="text/css" href="${re.contextPath}/plugin/layui/dropdown_2.3.3/dropdown.css">
    <!--extended-->
    <link rel="stylesheet" type="text/css" href="${re.contextPath}/plugin/common/css/extended.css"/>
    <!--公用样式JS-->
    <script type="text/javascript" src="${re.contextPath}/plugin/jquery/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="${re.contextPath}/plugin/common/js/comment.js"></script>
    <#--<script type="text/javascript" src="${re.contextPath}/plugin/layui/layui.js" charset="utf-8"></script>-->
    <script type="text/javascript" charset="utf-8" src="${re.contextPath}/plugin/common/js/tabs.js"></script>
    <script type="text/javascript" charset="utf-8" src="${re.contextPath}/plugin/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="${re.contextPath}/plugin/ueditor/ueditor.all.min.js"></script>
    <!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
    <!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
    <script type="text/javascript" charset="utf-8" src="${re.contextPath}/plugin/ueditor/lang/zh-cn/zh-cn.js"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<style>
    .Right {
        width: 100%;
        overflow-y: scroll;
    }

    .layui-input-s:hover{
        height: 36px;
        border: 2px solid #5775EF;
        border-radius: 3px;
        padding: 0 10px;
    }

</style>
<body>
<div class="container clearfix">

    <!--右侧内容-->
    <div class="Right fr">
        <div class="screening screeningOne whitebg clearfix">

            <div class="supply fl" style="width: 35%">
                <ul class="clearfix blue">
                    关键词
                </ul>
                <div class="clearfix" style="width: 100%">
                    <input name="" placeholder="关键词" style="width: 90%;" class="layui-input-s" onkeyup="searchselect(this)"
                           autoComplete="off" id="searchKey">
                </div>
            </div>
            <div class="supply fl" style="width: 50%">
                <ul class="clearfix blue">
                    文档上传时间
                </ul>
                <div class="clearfix" style="width: 100%">
                    <input id="beginDate" type="text" style="width: 30%;" autoComplete="off" placeholder="开始时间"
                           class="fl"/>
                    <span class="fl">
                       &nbsp;至&nbsp;
                         </span>
                    <input id="endDate" type="text" style="width: 30%;" autoComplete="off" placeholder="结束时间"
                           class="fl"/>


                    <button type="button" class="bluebg white bor0 fr ft18" style="margin-left: 12px;width: 120px;"
                            onclick="query()">查询
                    </button>
                </div>
            </div>

        </div>
        <!--分页-->
        <div class="screening screeningOne whitebg clearfix">
            <div id="wjre">
            </div>
            <!--tab页面-->
            <div class="layui-tab layui-tab-brief" lay-filter="demo">
                <ul id="tab-uls" class="layui-tab-title" style="margin: 0px 10px 10px 10px">
                    <li class="layui-this tab-name-select" lay-data="{index:'0'}" style="width: 10%;">综合</li>
                    <li class="tab-name-unselect" lay-data="{index:'1'}" style="width: 10%;">最热</li>
                    <li class="tab-name-unselect" lay-data="{index:'2'}" style="width: 10%;">最新</li>
                    <li class="tab-name-unselect" lay-data="{index:'3'}" style="width: 10%;">点赞</li>
                </ul>
                <div class="layui-tab-content" style="height: auto;">
                    <div class="layui-tab-item layui-show" style="margin-left: 0px">
                        <ul>
                        </ul>
                        <div id="pageFy0"></div>
                    </div>
                    <div class="layui-tab-item" style="margin-left: 0px">

                        <ul>
                        </ul>
                        <div id="pageFy1"></div>
                    </div>
                    <div class="layui-tab-item" style="margin-left: 0px">
                        <ul>
                        </ul>
                        <div id="pageFy2"></div>
                    </div>
                    <div class="layui-tab-item" style="margin-left: 0px">
                        <ul>
                        </ul>
                        <div id="pageFy3"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>

</div>


<div class="layui-btn-container"></div>
<script type="text/javascript" src="${re.contextPath}/plugin/layui2.6.7/layui.js" charset="utf-8"></script>
<script type="text/javascript" src="${re.contextPath}/plugin/tools/tool.js"></script>
<#--<script type="text/javascript" charset="utf-8" src="${re.contextPath}/plugin/layui/dropdown_2.3.3/dropdown.js"></script>-->
<script type="text/javascript" charset="utf-8" src="${re.contextPath}/plugin/common/js/tabs.js"></script>

<!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->

<script>


    var layer, form, laydate, upload, uploadListIns, element, tableIns, table, laypage;
    var layuiCurrPage = 1;
    var wjnum;
    var searchKey;
    var searchKeyWord;
    var sssdropdown;
    var selectdata = new Array();
    var loadindex;
    var xla;

    $(function () {
        layui.use(['dropdown', 'form', 'layer', 'element', 'table', 'laydate', 'laypage'], function () {
            laydate = layui.laydate;
            form = layui.form;

            element = layui.element;
            table = layui.table;
            laydate = layui.laydate;
            laypage = layui.laypage;
            sssdropdown = layui.dropdown
            //执行一个laydate实例
            laydate.render({
                elem: '#beginDate', //指定元素
                value:""
            });
            laydate.render({
                elem: '#endDate' //指定元素
            });
            xla= sssdropdown.render({
                elem: '#searchKey'
                , data: selectdata
                , click: function (obj) {
                    this.elem.val(obj.title);
                }
                , style: 'width: 235px;'
            });
            // 默认查询 一个月之前的
           var  that= $('.layui-tab-title li').eq(0);
            var url = "/search/znSerch/queryFileList?type=0";
            searchKey = "";
            var jsonc = {searchKey: "",beginDate:"",endDate:""};
            doQuery(url, jsonc, that, 0);

        });



        $('.layui-tab-title li').on('click', function (i, v) {
            var that = $(this);
            var laydata = eval('(' + $(this).attr("lay-data") + ')');
            var index = laydata.index;
            var url = "/search/znSerch/queryFileList?type=" + index;
            searchKey = $("#searchKey").val();
            var beginDate = $("#beginDate").val();
            var endDate = $("#endDate").val();
            var jsonc = {searchKey: searchKey,beginDate:beginDate,endDate:endDate};
            doQuery(url, jsonc, that, index);
        });


    });


    /**获取近N天*/
    function getRecentDay(day){
        var today = new Date();
        var targetday_milliseconds=today.getTime() + 1000*60*60*24*day;
        today.setTime(targetday_milliseconds);
        var tYear = today.getFullYear();
        var tMonth = today.getMonth();
        var tDate = today.getDate();
        tMonth = doHandleMonth(tMonth + 1);
        tDate = doHandleMonth(tDate);
        return tYear+"-"+tMonth+"-"+tDate;
    }
    function doHandleMonth(month) {
        var m = month;
        if (month.toString().length == 1) {
            m = "0" + month;
        }
        return m;

    }


    function   searchselect(object) {
        var searchKey = $(object).val().trim();
        selectdata=[];
       // $(".layui-dropdown-menu").find("li").remove()
        var  jsonc={
            searchKey:searchKey
        }
        if (searchKey) {
            layerAjaxGet('/search/znSerch/querykeywordYi',jsonc,'',function (d) {
                if (d.flag == true) {
                    if (d.data) {
                        var arr = d.data.split(',');
                        for (var i = 0; i < arr.length; i++) {
                            selectdata.push({
                                title: arr[i]
                                , id: arr[i]
                            })

                        }
                    }
                } else {
                    layer.msg(d.msg, {icon: 2});
                }
                console.log($(xla))
                xla.reload({
                    data:selectdata,
                    show: true //重载即显示
                })
            })
        }

    }

    function ggSlect(object) {
        setTimeout(function() {
            $("#searchKey").val($(object).html());
        }, 20);




    }


    //热词搜索
    function hotWord(object) {
        var jsondata = {
            projectName: $(object).text()
        };
        table.reload('tableList', {where: jsondata});
    }


    $(function () {
        //回车事件
        $(document).keydown(function(e){
            // 兼容FF和IE和Opera
            var theEvent = e || window.event;
            var code = theEvent.keyCode || theEvent.which || theEvent.charCode;
            if (code == 13) {
                query();
            }
            return true;
        });
    })

    function query() {
        //loading = layer.msg('提示：文件过大等候时间会长。正在上传。。', {icon: 16, shade: 0.3, time:0});
        var that = $(".layui-this");
        var laydata = eval('(' + $(that).attr("lay-data") + ')');
        var index = laydata.index;
        var url = "/search/znSerch/queryFileList?type=" + index;
        searchKey = $("#searchKey").val();
        var beginDate = $("#beginDate").val();
        var endDate = $("#endDate").val();
        var jsonc = {
            searchKey: searchKey,
            beginDate: beginDate,
            endDate: endDate
        };
        doQuery(url, jsonc, that, index);

    }

    function doQuery(url, jsonc, that, index) {
        loadindex=layer.load(1);
        layerAjaxGet(url, jsonc, '', function (d) {
            if (d.flag == true) {
                layer.close(loadindex);
                var totalsize=d.msg;
                that.parent().next().find(".layui-tab-item").eq(index).find("ul").html("");
                var lcdata = d.data;
                wjnum = lcdata.length;
                var searchKey = $("#searchKey").val();
                var str = searchKey + "共有" + totalsize + "条搜索结果";
                if (searchKey) {
                    str = "<span style='color: red'>" + searchKey + "文件</span>" + "共有" + totalsize + "条搜索结果";
                } else {
                    str = "共有" + totalsize + "条搜索结果";
                }

                $("#wjre").html(str)

                pageFy(lcdata, index, that,totalsize);
            } else {
                layer.msg(d.msg, {icon: 2});
            }
        });
    }

    function dzClick(id) {
        var json = {
            id: id
        }
        layerAjax('/search/znSerch/updateDz', json, '', function (d) {
            if (d.flag == true) {
                var data1 = d.data;
                if (data1.flag == 1) {
                    $(".dz_span_" + id).find("img:eq(0)").attr("src", "${re.contextPath}/plugin/common/images/dzy.png\\")
                    $(".dz_span_" + id).css("color", "red");

                } else {
                    $(".dz_span_" + id).find("img:eq(0)").attr("src", "${re.contextPath}/plugin/common/images/dz.png\\")
                    $(".dz_span_" + id).removeAttr("style");
                }
                layer.msg(d.msg, {icon: 1});
            } else {
                layer.msg(d.msg, {icon: 2});
            }
        });

    }

    function dofileName(url) {
        var index = url.lastIndexOf(".");
        var ext = url.substr(0, index);
        return ext;
    }

    function reFileType(url) {
        var fileType = "";
        var index = url.lastIndexOf(".");
        var ext = url.substr(index + 1);
        //图片数组
        var imagearray = ['png', 'jpg', 'jpeg', 'bmp', 'gif', 'webp', 'psd', 'svg', 'psd'];
        if (imagearray.indexOf(ext.toLowerCase()) !== -1) {
            fileType = "图片";
        }
        var filearray = ['doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx','pdf'];
        if (filearray.indexOf(ext.toLowerCase()) !== -1) {
            fileType = "文档";
        }
        var pafarray = ['mp4', 'avi', 'wmv', 'mpg', 'rm', 'swf', 'mpeg'];
        if (pafarray.indexOf(ext.toLowerCase()) !== -1) {
            fileType = "视频";
        }
        return fileType;
    }

    function refileTypeSpan(fileType) {
        var spanType = "<span  style='color: blue;background-color: #EEF1FE;width: 40px;display: inline-block;text-align: center;'>" + fileType + "</span>";
        return spanType;

    }

    function detailClick(id, fileName, spanType) {
        window.parent._showtab('xm_v' + id, fileName, "/search/znSerch/viewDetail?id=" + id + "&type=" + encodeURI(spanType));
    }

    function doKeyword(searchKeyWord) {
        var str = "";
        if (!searchKeyWord) {
            searchKeyWord = "";
        } else {
            var words = searchKeyWord.split(",");
            if (words.length == 1) {
                words = searchKeyWord.split("，");
            }
            for (var i = 0; i < words.length; i++) {
                var wr = words[i];
                var arr = searchKey.split(" ");
                for(var y = 0;y<arr.length;y++){
                    var s = arr[y];
                    wr = wr.replace(s, "<span style='color: red;'>" + s + "</span>");
                }
                str = str + wr + "&nbsp;&nbsp;";

            }
        }
        return str;
    }

    function dopl(isDz, id) {
        var plstr = "";
        if (isDz == 0) {
            plstr = " <span   id=\"dz_span_" + id + "\"  class=\"dz_span_" + id + "\"    onclick=\"dzClick('" + id + "')\"   > <img  style=\"width:25px;\" src=\"${re.contextPath}/plugin/common/images/dz.png\"  alt=\"\" >&nbsp;点赞&nbsp;&nbsp;&nbsp;&nbsp;";
        } else {
            plstr = " <span   style=\"color:red\"    id=\"dz_span_" + id + "\"  class=\"dz_span_" + id + "\"    onclick=\"dzClick('" + id + "')\" > <img  style=\"width:25px;\" src=\"${re.contextPath}/plugin/common/images/dzy.png\"   alt=\"\" >&nbsp;点赞&nbsp;&nbsp;&nbsp;&nbsp;";
        }
        return plstr;

    }

    function pageFy(data, index, that,totalsize) {
        var index_v = index;
        laypage.render({
            elem: 'pageFy' + index_v
            , count: totalsize
            , curr: layuiCurrPage
            , layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
            , jump: function (obj,first) {
                //模拟渲染
                that.parent().next().find(".layui-tab-item").eq(index_v).find("ul").html("");
                var  start=obj.curr * obj.limit - obj.limit;
                var  size =obj.limit;
                if(!first){
                    var url = "/search/znSerch/queryFileList?type=" + index;
                    var searchKey = $("#searchKey").val();
                    var beginDate = $("#beginDate").val();
                    var endDate = $("#endDate").val();
                    var jsonc = {
                        searchKey: searchKey,
                        beginDate: beginDate,
                        endDate: endDate,
                        start:start,
                        size:size
                    };
                    loadindex=layer.load(1);
                    layerAjaxGet(url, jsonc, '', function (d) {
                        if (d.flag == true) {
                            layer.close(loadindex);
                            that.parent().next().find(".layui-tab-item").eq(index).find("ul").html("");
                            var lcdata = d.data;
                            // 从新获取数据
                            eachdata(lcdata,index_v,that)
                        } else {
                            layer.msg(d.msg, {icon: 2});
                        }
                    });

                }else{
                    eachdata(data,index_v,that)
                }


            },
            end: function () {
                console.log("endd.......")
            }
        });

        $(".layui-laypage-limits").find("select").css("width", "80px");
        layuiCurrPage = 1;
    }

    function eachdata(lcdata,index_v,that) {
        layui.each(lcdata, function (index, item) {
            var fileName = item.fileName;
            var isDz = item.isDz;
            var scflag = item.scflag;
            var id = item.id;
            var newstr="";
            var hotdaydic='${hotdaydic}';
            var newdaydic='${newdaydic}';
            if(newdaydic){
                if(parseFloat(item.days)<=parseFloat(newdaydic)){
                    newstr = "<span  style='color: blue;width: 40px;display: inline-block;text-align: center;font-style:italic ;font-weight: bolder;'>new</span>";
                }

            }else{
                if(item.days<=7){
                    newstr = "<span  style='color: blue;width: 40px;display: inline-block;text-align: center;font-style:italic ;font-weight: bolder;'>new</span>";
                }
            }
            var hotstr="";
            if(hotdaydic){
                if(parseFloat(item.hotnum)>=parseFloat(hotdaydic)) {
                    hotstr = "<img src=\"/plugin/common/images/84@2x.png\"  style='margin-bottom: 3px' class=\"\">";
                }
            }else{
                if(parseFloat(item.hotnum)>=parseFloat(100)) {
                    hotstr = "<img src=\"/plugin/common/images/84@2x.png\" style='margin-bottom: 3px'   class=\"\">";
                }
            }

            var  scstr="";
            if(scflag>0){
                scstr = "<img src=\"/plugin/common/images/wjsc.png\"  style='margin-bottom: 3px;width: 24px;' class=\"\">";
            }
            var fileType = reFileType(fileName);
            var spanType = refileTypeSpan(fileType);
            fileName = dofileName(fileName);
            var file_name = fileName;
            var arr = searchKey.split(" ");
            for(var i = 0;i<arr.length;i++){
                var s = arr[i];
                fileName = fileName.replace(s, "<span style='color: red;'>" + s + "</span>");
            }
            var searchKeyWord = item.searchKey;
            var str = doKeyword(searchKeyWord);
            var plstr = dopl(isDz, id);
            that.parent().next().find(".layui-tab-item").eq(index_v).find("ul").append("    <li class=\"clearfix cursor-default\"  style='width: 100%;border-bottom:1px solid #ccc;padding-bottom: 20px;margin-bottom: 20px;'>\n" +
                "                                        <div class=\"w90p\" ><span style='font-weight: bolder' class=\"cursor ft20\" onclick=\"detailClick('" + id + "','" + file_name + "','" + fileType + "')\" > " + fileName + " </span>" + spanType + "&nbsp;"+newstr+"&nbsp;"+hotstr+"&nbsp;"+scstr+"</div>\n" +
                "                                        <span  style=\"display:block;\">关键词：" + str + "</span>\n" +
                "                                     " + plstr + "</span><span onclick=\"detailClick('" + id + "','" + file_name + "','" + fileType + "')\"><img src=\"${re.contextPath}/plugin/common/images/pl.png\"  style=\"width:25px;\" alt=\"\">&nbsp;评论</span>\n" +
                "                                    </li>");

        });



    }


</script>


</body>
</html>
